package m.toolkit.rrd4j;

import java.util.ArrayList;
import java.util.List;

import m.toolkit.rrd4j.DataSource.DataSourceType;
import m.toolkit.rrd4j.Rra.ConsolidationFunction;

/**
 * @author ming
 * @date 2014年2月24日下午9:02:55
 */
public class Create {
	private String fileName;
	private List<DataSource> ds;
	private List<Rra> rra;
	// 期望多长时间取到值,60为1分钟
	private Integer step;
	// 数据最找记录时间,默认是当前时间减去 600*300秒
	private Long start;

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public List<DataSource> getDs() {
		return ds;
	}

	public void setDs(List<DataSource> ds) {
		this.ds = ds;
	}

	public Integer getStep() {
		return step;
	}

	public void setStep(Integer step) {
		this.step = step;
	}

	public Long getStart() {
		return start;
	}

	public void setStart(Long start) {
		this.start = start;
	}

	public List<Rra> getRra() {
		return rra;
	}

	public void setRra(List<Rra> rra) {
		this.rra = rra;
	}

	public void addDs(String name, DataSourceType dst) {
		if (ds == null) {
			ds = new ArrayList();
		}
		DataSource d = new DataSource();
		d.setDst(dst);
		d.setName(name);
		d.setHeartbeat(120);
		d.setMin("U");
		d.setMax("U");
		ds.add(d);
	}

	public void createDeafultRra(ConsolidationFunction cf) {
		rra = new ArrayList();
		rra.add(rra(cf, "0.5", 1, 60));// hour
		rra.add(rra(cf, "0.5", 5, 288));// day
		rra.add(rra(cf, "0.5", 30, 336));// week
		rra.add(rra(cf, "0.5", 120, 360));// month
		rra.add(rra(cf, "0.5", 1440, 366));// year
	}

	private Rra rra(ConsolidationFunction cf, String xff, int step, int row) {
		Rra rra = new Rra();
		rra.setCf(cf);
		rra.setXff(xff);
		rra.setSteps(step);
		rra.setRows(row);
		return rra;
	}

}
